home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch5 / MultiPrv.frm (.txt) < prev    next >
Visual Basic Form  |  1999-04-17  |  4KB  |  132 lines

  1. VERSION 5.00
  2. Begin VB.Form frmPreview 
  3.    Caption         =   "Preview"
  4.    ClientHeight    =   3195
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3195
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.HScrollBar hbarMarble 
  13.       Height          =   255
  14.       Left            =   0
  15.       TabIndex        =   3
  16.       Top             =   2400
  17.       Width           =   2295
  18.    End
  19.    Begin VB.VScrollBar vbarMarble 
  20.       Height          =   2295
  21.       Left            =   2400
  22.       TabIndex        =   2
  23.       Top             =   0
  24.       Width           =   255
  25.    End
  26.    Begin VB.PictureBox picOuter 
  27.       Height          =   2295
  28.       Left            =   0
  29.       ScaleHeight     =   2235
  30.       ScaleWidth      =   2235
  31.       TabIndex        =   0
  32.       Top             =   0
  33.       Width           =   2295
  34.       Begin VB.PictureBox picInner 
  35.          AutoSize        =   -1  'True
  36.          Height          =   6045
  37.          Left            =   360
  38.          ScaleHeight     =   5985
  39.          ScaleWidth      =   6165
  40.          TabIndex        =   1
  41.          Top             =   240
  42.          Width           =   6225
  43.       End
  44.    End
  45. Attribute VB_Name = "frmPreview"
  46. Attribute VB_GlobalNameSpace = False
  47. Attribute VB_Creatable = False
  48. Attribute VB_PredeclaredId = True
  49. Attribute VB_Exposed = False
  50. Option Explicit
  51. ' Arrange the scroll bars.
  52. Private Sub ArrangeControls()
  53. Dim border_width As Single
  54. Dim got_wid As Single
  55. Dim got_hgt As Single
  56. Dim need_wid As Single
  57. Dim need_hgt As Single
  58. Dim need_hbar As Boolean
  59. Dim need_vbar As Boolean
  60.     ' See how much room we have and need.
  61.     border_width = picOuter.Width - picOuter.ScaleWidth
  62.     got_wid = ScaleWidth - border_width
  63.     got_hgt = ScaleHeight - border_width
  64.     need_wid = picInner.Width
  65.     need_hgt = picInner.Height
  66.     ' See if we need the horizontal scroll bar.
  67.     If need_wid > got_wid Then
  68.         need_hbar = True
  69.         got_hgt = got_hgt - hbarMarble.Height
  70.     End If
  71.     ' See if we need the vertical scroll bar.
  72.     If need_hgt > got_hgt Then
  73.         need_vbar = True
  74.         got_wid = got_wid - vbarMarble.Width
  75.         ' See if we now need the horizontal scroll bar.
  76.         If (Not need_hbar) And need_wid > got_wid Then
  77.             need_hbar = True
  78.             got_hgt = got_hgt - hbarMarble.Height
  79.         End If
  80.     End If
  81.     ' Arrange the controls.
  82.     picOuter.Move 0, 0, got_wid + border_width, got_hgt + border_width
  83.     If need_hbar Then
  84.         hbarMarble.Move 0, got_hgt + border_width, got_wid + border_width
  85.         hbarMarble.Min = 0
  86.         hbarMarble.Max = picInner.ScaleWidth - got_wid
  87.         hbarMarble.SmallChange = got_wid / 5
  88.         hbarMarble.LargeChange = got_wid
  89.         hbarMarble.Visible = True
  90.     Else
  91.         hbarMarble.Value = 0
  92.         hbarMarble.Visible = False
  93.     End If
  94.     If need_vbar Then
  95.         vbarMarble.Move got_wid + border_width, 0, vbarMarble.Width, got_hgt + border_width
  96.         vbarMarble.Min = 0
  97.         vbarMarble.Max = picInner.ScaleHeight - got_hgt
  98.         vbarMarble.SmallChange = got_hgt / 5
  99.         vbarMarble.LargeChange = got_hgt
  100.         vbarMarble.Visible = True
  101.     Else
  102.         vbarMarble.Value = 0
  103.         vbarMarble.Visible = False
  104.     End If
  105. End Sub
  106. Private Sub Form_Load()
  107.     picInner.AutoSize = True
  108.     picInner.Move 0, 0
  109.     picInner.BorderStyle = vbBSNone
  110.     picInner.BackColor = vbWhite
  111.     picInner.AutoRedraw = True
  112. End Sub
  113. Private Sub Form_Resize()
  114.     ArrangeControls
  115. End Sub
  116. ' Reposition picInner.
  117. Private Sub hbarMarble_Change()
  118.     picInner.Left = -hbarMarble.Value
  119. End Sub
  120. ' Reposition picInner.
  121. Private Sub hbarMarble_Scroll()
  122.     picInner.Left = -hbarMarble.Value
  123. End Sub
  124. ' Reposition picInner.
  125. Private Sub vbarMarble_Change()
  126.     picInner.Top = -vbarMarble.Value
  127. End Sub
  128. ' Reposition picInner.
  129. Private Sub vbarMarble_Scroll()
  130.     picInner.Top = -vbarMarble.Value
  131. End Sub
  132.